<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title>

			测试poll push
			人员信息(编辑123)@#$%^&*(
		</title>
		<meta name="renderer" content="webkit">
		<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
		<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
		<meta name="apple-mobile-web-app-status-bar-style" content="black">
		<meta name="apple-mobile-web-app-capable" content="yes">
		<meta name="format-detection" content="telephone=no">
		<link rel="stylesheet" href="css/main.css" media="all">

		<style>
			.imgs {
				display: none;
			}

			input[type="file"] {
				width: 50px;
				height: 50px;
				border-radius: 100%;
				opacity: 0;
				cursor: pointer;
				border: 1px solid red;
				position: absolute;
			}
		</style>

	</head>
	<body>

		<div class="x-body">
			<form class="layui-form layui-form-pane" action="" id="add">
				<blockquote class="layui-elem-quote">
					<input type="hidden" name="id" value="8">
					<div>
						<input class="layui-upload " type="file" accept="undefined" id="previewImg" name="images"
							onchange="upload(this,8)">
						<img id="pimages" name="pimages" src="./images/tx.jpg" class="layui-circle"
							style="width:50px;height:50px;float:left" alt="个人头像">
						<input id="avatar" name="image" required="" type="hidden" value="./images/tx.jpg">
						<dl style="margin-left:80px; color:#019688">
							<dt><span id="usernameSpan">ADMIN</span> <span></span></dt>
							<dd style="margin-left:0" id="description">这家伙很懒，什么也没有留下</dd>
						</dl>
					</div>
				</blockquote>

				<div class="layui-tab layui-tab-brief" lay-filter="docDemoTabBrief">


					<div class="layui-tab-content">
						<div class="layui-tab-item layui-show">


							<div class="layui-form-item">
								<label class="layui-form-label">
									<span class='x-red'>*</span>用户名
								</label>
								<div class="layui-input-block">
									<input id="username" type="text" name="name" autocomplete="off"
										placeholder="空制在80个汉字，160个字符以内" class="layui-input" value="ADMIN">
								</div>
							</div>

							<div class="layui-form-item">
								<label class="layui-form-label">
									<span class='x-red'>*</span>电话号码
								</label>
								<div class="layui-input-block">
									<input id="telephone" type="text" name="phone" autocomplete="off" placeholder=""
										class="layui-input" value="15325644722">
								</div>
							</div>


							<div class="layui-form-item">
								<label class="layui-form-label">
									<span class='x-red'>*</span>密码
								</label>
								<div class="layui-input-block">
									<input id="password" type="password" name="password" value="" autocomplete="off"
										placeholder="" class="layui-input">
								</div>
							</div>
							<div class="layui-form-item">
								<label class="layui-form-label">
									<span class='x-red'>*</span>新密码
								</label>
								<div class="layui-input-block">
									<input id="newPassword" type="password" name="newpassword" value=""
										autocomplete="off" placeholder="新密码为空则不修改" class="layui-input">
								</div>
							</div>

							<div class="layui-form-item">
								<button class="layui-btn" type="button" lay-filter="add" lay-submit="">
									保存
								</button>
							</div>
							<!--</form>-->
							<div style="height:100px;"></div>
						</div>



					</div>

				</div>
			</form>
		</div>
		<script src="js/base.js"></script>
		<script src="js/md5.js"></script>
		<script>
			//数据初始化
			let id = localStorage.getItem("id");
			let username = localStorage.getItem("username");
			let icon = localStorage.getItem("icon");
			let telephone = localStorage.getItem("telephone");
			let description = localStorage.getItem("description");
			document.getElementById("usernameSpan").innerHTML = username;
			document.getElementById("description").innerHTML = description;
			document.getElementById("telephone").value = telephone;
			document.getElementById("username").value = username;
			
			let url="http://localhost:8080/wuye/UserController/showImg?fileName=";
			url=url+icon;
			
			rest(url,"get",null,function(r){
				document.getElementById("pimages").src="data:image/png;base64,"+r.data;
			});
			
			
		</script>
		<script src="lib/layui/layui.js" charset="utf-8"></script>
		<script src="js/x-layui.js" charset="utf-8"></script>

		<script>
			layui.use(['element', 'layer', 'form'], function() {
				$ = layui.jquery; //jquery
				lement = layui.element(); //面包导航
				layer = layui.layer; //弹出层
				form = layui.form()



				//图片上传接口
				/*layui.upload({
				  url: './upload.json' //上传接口
				  ,success: function(res){ //上传成功后的回调
				      console.log(res);
				    $('#LAY_demo_upload').attr('src',res.url);
				  }
				});*/


				//监听提交
				form.on('submit(add)', function(data) {
					let username = document.getElementById("username").value;
					let password = document.getElementById("password").value;
					if (password == null || password == "") {

					} else {
						password = md5(md5(password + "neuedu.com").toUpperCase() + "java01").toUpperCase();
					}

					let telephone = document.getElementById("telephone").value;
					let newPassword = document.getElementById("newPassword").value;
					if (newPassword == null || newPassword == "") {

					} else {
						newPassword = md5(md5(newPassword + "neuedu.com").toUpperCase() + "java01")
					.toUpperCase();
					}

					let icon = fileName;
					let url = "http://localhost:8080/wuye/UserController/editSelfInfo";
					let method = "post";
					let json = {};
					json.userId = id;
					json.username = username;
					json.password = password;
					json.telephone = telephone;

					json.newPassword = newPassword;
					json.icon = icon;

					rest(url, method, json, function(r) {
						if (r.code == 200) {
							layer.msg(r.msg, {
								icon: 6,
								time: 2000
							}, function() {
								window.parent.location.reload();
								var index = parent.layer.getFrameIndex(window.name);
								parent.layer.close(index);
							});
						} else {
							layer.msg(r.msg, {
								icon: 5,
								time: 2000
							});
						}
					});
					return false;
					// var name = $("input[name='name']").val();

					// if (name == "") {
					// 	layer.msg('用户名不能为空', {
					// 		icon: 5,
					// 		time: 2000
					// 	});
					// 	return false;
					// }

					// var data = data.field;
					// $.ajax({
					// 	type: "post",
					// 	url: "xxx",
					// 	data: data,
					// 	dataType: "json",
					// 	success: function(data) {
					// 		//alert(1);
					// 		if (data.status == 1) {
					// 			layer.msg(data.info, {
					// 				icon: 6,
					// 				time: 2000
					// 			}, function() {
					// 				window.parent.location.reload();
					// 				var index = parent.layer.getFrameIndex(window.name);
					// 				parent.layer.close(index);
					// 			});
					// 			return false;

					// 		} else {
					// 			layer.msg(data.info, {
					// 				icon: 5,
					// 				time: 2000
					// 			});
					// 			return false;
					// 		}
					// 	}

					// });

				});

			})
		</script>
		<!--栏目缩略图上传-->

		<script>
			// let avatar = document.getElementById("avatar");
			// avatar.onchange = function() {

			// }

			// function handleFile(files) {
			// 	if (files.length > 1) {
			// 		alert("最多选择一张")
			// 		return;
			// 	}
			// 	if (files[0]) {
			// 		let srcValue = window.URL.createObjectURL(files[0]);
			// 		document.getElementById("pimages").src = srcValue;
			// 	}

			// }

			let fileName = null;

			function upload(obj, id) {
				// let avatar = document.getElementById("avatar");
				// handleFile(avatar.files);

				// var formData = new FormData();
				// formData.append('images', $('#previewImg')[0].files[0]);
				// formData.append('id', id);
				layer.msg('图片上传中', {
					icon: 16
				});
				let file = $('#previewImg')[0].files[0];
				let srcValue = window.URL.createObjectURL(file);
				document.getElementById("pimages").src = srcValue;
				let url = "http://localhost:8080/wuye/UserController/uploadIcon";
				let method = "post";
				let json = {};
				json.userId = id;

				let reader = new FileReader();
				reader.onload = function() {
					json.base64 = this.result;
					json.base64 = json.base64.substring(json.base64.indexOf(",") + 1);
					rest(url, method, json, function(r) {
						// alert(r.data);
						fileName = r.data;
					});
				};
				reader.readAsDataURL(file);



				// $.ajax({
				//     type:"post",
				//     processData: false,
				//     contentType: false,
				//     url:"xxx",
				//     data:formData,
				//     success:function(data){
				//         if(data.status == 1){
				//             console.log(data.image_name);
				//             layer.closeAll('loading');
				//             //layer.msg(data.info,{icon:1,time:1000});
				//             $("#pimages").attr('src',data.image_name);
				//             $("#avatar").val(data.image_name);
				//             $(".imgs").show();
				//             return false;
				//         }else{
				//             layer.msg(data.info,{icon:2,time:1000});
				//         }
				//     }
				// });
			}
		</script>

	</body>
</html>